package swordoffer.offer45;

import java.util.Arrays;
import java.util.Comparator;

public class CustomSort {
    public String minNumber(int[] nums) {
        String[] strs = new String[nums.length];
        // 1. 转换成字符串数组
        for (int i = 0; i < nums.length; i++) {
            strs[i] = String.valueOf(nums[i]);
        }
        // 2. 使用内置函数
        Arrays.sort(strs, new Comparator<String>() {
            public int compare(String a, String b) {
                return (a + b).compareTo(b + a);
            }
        });
        // 3. 拼接
        StringBuilder res = new StringBuilder();
        for (String str : strs) {
            res.append(str);
        }
        return res.toString();
    }
}
